package me.zzp;

import me.zzp.model.User;
import me.zzp.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author zhangzepeng
 */
@SpringBootApplication
public class Application implements CommandLineRunner {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    private UserService userService;

    @Override
    public void run(String... strings) throws Exception {
        User user = userService.create("Joe");
        System.out.println(user);
        System.out.println();

        user.setName("redraiment");
        user = userService.update(user);
        System.out.println(user);
        System.out.println();

        user.setName("Joe");
        user.setVersion(1);
        userService.update(user);
        System.out.println(user);
        System.out.println();

        userService.create("Joe");
        System.out.println(userService.delete(user));
        userService.all().forEach(System.out::println);
        System.out.println();

        System.out.println(userService.deleteForce(user));
        userService.all().forEach(System.out::println);

        System.exit(0);
    }
}
